var path = require('path');
var webpack = require('webpack');
var HtmlwebpackPlugin = require('html-webpack-plugin');

var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, 'WebApp');
var BUILD_PATH = path.resolve(ROOT_PATH, 'build');

module.exports = {
    entry: {
        main:path.resolve(APP_PATH, 'index.js'),
        vendor:["jquery",'immutable','react']
    },

    output: {
        path: APP_PATH,
        filename: '[name].[chunkhash:8].js',
        publicPath:'/WebApp',
        chunkFilename: "[id].[chunkhash:8].chunk.js"
    },

    //enable dev source map
    devtool: 'eval-source-map',
    //enable dev server
    devServer: {
        port:8090,
        hot: true,
        historyApiFallback: {
            index: '/WebApp/app.html'
        }
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                loader: 'babel',
                include: APP_PATH,
                exclude: /node_modules/,
                query: {
                    //添加两个presents 使用这两种presets处理js或者jsx文件
                    presets: ['es2015', 'react']
                }
            },
            {
                test: /\.scss$/,
                loaders: ['style', 'css?sourceMap', 'sass?sourceMap'],
                include: APP_PATH
            },
            {
                test: /\.less$/,
                loaders: "style!css!less",
                include: APP_PATH
            },
            {
                test: /\.css$/,
                loaders: ['style', 'css?sourceMap'],
                include: ROOT_PATH
            },
             {
                test: /\.(png|jpg)$/,
                exclude: /^node_modules$/,
                loader: 'url?limit=1&name=[name].[ext]' //注意后面那个limit的参数，当你图片大小小于这个限制的时候，会自动启用base64编码图片
            }
        ],
        //postLoaders: [
        //    {
        //        test: /\.js$/,
        //        loaders: ['es3ify-loader']
        //    }
        //]
    },
    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin('vendor','vendor.js'),
        new HtmlwebpackPlugin({
            template: path.resolve(APP_PATH, 'index.html'),
            filename: 'app.html',
            // //chunks这个参数告诉插件要引用entry里面的哪几个入口
             chunks: ['main','vendor'],
            // //要把script插入到标签里
               inject: 'body'
            // title: 'Hello World app'
        })
    ]
};